package com.example.mvpdemo.retrofit;

import com.example.mvpdemo.util.Constants;
import com.example.mvpdemo.util.FireGsonUtil;
import com.example.mvpdemo.util.LogUtils;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Date:2019/12/13
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 */
public class HttpRequest {

    public static HttpRequestUtils.RequestThread getUploadLog(HttpCallBack responseListener,String feedbackId,String fileName) {
        if (responseListener == null) {
            return null;
        }
        Map<String, String> params = new HashMap<>();
        String url = Constants.BASE_SERVER_URL + Constants.UPLOAD_LOG_URL + "?feedbackId="+feedbackId + "&file="+fileName;
        params.put("url", url);
        params.put("Method", "POST");
        params.put("body","{}");
        HttpRequestUtils.RequestThread requestThread = new HttpRequestUtils.RequestThread(params, responseListener);
        requestThread.start();
        return requestThread;
    }

    public static void upLoadLog(HttpOnResponseCallBack callBack,String feedbackId,String fileName){
            getUploadLog(httpResult -> {
                if ((httpResult != null ? httpResult.getData() : null) == null) {
                    return;
                }
                try {
                    String content = httpResult.getData().toString();
                    if (httpResult.isSuccess()) {
                        callBack.onResponse(content);
                    } else {
                        String message = httpResult.getMessage();
                        callBack.onFailed(message);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            },feedbackId,fileName);
    }
}
